<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>自定义表单更多版本</title>
    <#include "/pubHeadStyle.html">
</head>
<body>
<div style="overflow-y:scroll;">
    <div class="" style="height:706px;">
        <table class="layui-hide" id="customVersion" lay-filter="customVersion" style="width:100%;align:center;"></table>
    </div>
    <div style="position: absolute;bottom:6px;left:48%;">
        <button class="layui-btn layui-btn-danger" onclick="closeVersions()" lay-filter="closeVersions">关闭</button>
    </div>
</div>
<script type="text/html" id="operation">
    {{# if (d.isDefault === 1){ }}
    <a lay-event="" disabled="disabled" style="cursor: pointer">
        <span class="layui-icon layui-icon-set-sm"></span>
        <span style="color: #777777">设置默认</span>
    </a>
    {{# }else{ }}
    <a class=" " lay-event="setDefaultVersion" style="cursor: pointer">
        <span class="layui-icon layui-icon-set-sm"></span>
        <span>设置默认</span>
    </a>
    {{# } }}
    {{# if (d.isPublished === 1){ }}
    <a class=" " lay-event="newVersion" style="cursor: pointer">
        <span class="layui-icon layui-icon-add-1"></span>新建版本
    </a>
    {{# }else{ }}
    <a class=" " lay-event="publish" style="cursor: pointer">
        <span class="layui-icon layui-icon-circle"></span>发布
    </a>
    {{# } }}
    <a  lay-event="edit" style="cursor: pointer"><span class="layui-icon layui-icon-edit"></span>编辑</a>
    <a  lay-event="detailed" style="cursor: pointer"><span class="layui-icon layui-icon-file"></span>查看</a>
    <a  lay-event="preview" style="cursor: pointer"><span class="layui-icon layui-icon-file-b"></span>预览</a>
    <a  lay-event="setPublic" style="cursor: pointer"><span class="layui-icon layui-icon-set-sm"></span>设置是否公开</a>
    {{# if (d.isDefault === 0){ }}
    <a  lay-event="del" style="cursor: pointer"><span class="layui-icon layui-icon-delete"></span>删除</a>
    {{# } }}
</script>
<script>
    layui.config({
        base: serverPath.formPath + staticPath.formPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index', 'table', 'form', 'jquery','setter','util'], function () {
        var formKey = '${formKey}';
        var table = layui.table
            , setter = layui.setter
            , $ = layui.jquery
            , util = layui.util;

        table.render({
            elem: '#customVersion'
            , url: serverPath.formPath + setter.formLinkPath +'formDef/versions?formKey='+formKey
            , title: '表单版本'
            , cols: [[
                {field: 'versionNo', title: '版本号', align: 'center',minWidth:50}
                , {field: 'publishedBy', title: '发布人', align: 'center',minWidth:100,
                	templet:function(d){
                		if(d.isPublished=='1'){
                			 return d.publishedBy
                		}else{
                			return ''
                		}
                	}
                	
                }
                , {
                    field: 'publishTime', title: '发布时间', align: 'center',minWidth:120,
                    templet:function (d) {
                    	if(d.isPublished=='1'){
                    		 var formatPublishTime = util.toDateString(d.publishTime,"yyyy-MM-dd");
                             return formatPublishTime;
                    	}else{
                    		var formatPublishTime = "";
                            return formatPublishTime;
                    	}
                       
                    }
                }
                , {
                    field: 'isDefault', title: '是否默认', align: 'center',minWidth:90,
                    templet: function (d) {
                        if (d.isDefault === 1) {
                            return '<span style="color:green;">'+'是'+'</span>';
                        }
                        return '<span style="color:red;">'+'否'+'</span>';
                    }
                }
                , {
                    field: 'isPublished', title: '是否发布', align: 'center',minWidth:90,
                    templet: function (d) {
                        if (d.isPublished === 1) {
                            return '<span style="color:green;">'+'已发布'+'</span>';
                        }
                        return '<span style="color:red;">'+'未发布'+'</span>';
                    }
                }
                , {
                    field: 'isPublic', title: '是否公开', align: 'center',minWidth:90,
                    templet: function (d) {
                        if (d.isPublic === 1) {
                            return '<span style="color:green;">'+'公开'+'</span>';
                        }
                        return '<span style="color:red;">'+'未公开'+'</span>';
                    }
                }
                , { title: '管理', toolbar: '#operation', minWidth: 500, align: 'center'}
            ]]
            ,done:function (res,curr,count) {
                var allTh = $('th');
                allTh.addClass("colorSwitch");
                allTh.css("color","#fff");
                $('tr').css({'color':'black'});
            }
        });

        //管理栏事件
        table.on('tool(customVersion)', function (obj) {
            var formDefId=obj.data.formDefId;
            switch (obj.event) {
                //设置默认
                case 'setDefaultVersion':
                    $.ajax({
                        url: serverPath.formPath + setter.formLinkPath +"formDef/setDefaultVersion",
                        data: {"formDefId": formDefId},
                        dataType:'json',
                        success: function (data) {
                            layer.msg(data.msg);
                            //执行重载
                            table.reload('customVersion', {
                                page: {
                                    curr: 1
                                }
                            });
                        }
                    });
                    break;
                //发布
                case 'publish':
                    $.ajax({
                        url: serverPath.formPath + setter.formLinkPath +"formDef/publish",
                        data: {"formDefId": formDefId},
                        dataType:'json',
                        success: function (data) {
                            layer.msg(data.msg);
                            //执行重载
                            table.reload('customVersion', {
                                page: {
                                    curr: 1
                                }
                            });
                        }
                    });
                    break;
                case 'newVersion':
                    $.ajax({
                        url: serverPath.formPath + setter.formLinkPath +"formDef/newVersion",
                        data: {"formDefId": formDefId},
                        dataType:'json',
                        success: function (data) {
                            layer.msg(data.msg);
                            //执行重载
                            table.reload('customVersion', {
                                page: {
                                    curr: 1
                                }
                            });
                            parent.layui.table.reload('customForm');
                        }
                    });
                    break;
                case 'edit':
                    window.open(serverPath.formPath + setter.formLinkPath +'formDef/view/formDesign/formDevise?formDefId='+formDefId);
                    break;
                case 'detailed':
                    layer.open({
                        type: 2,
                        title: "查看",
                        shade: 0.3,
                        area: ['990px', '530px'],
                        content: serverPath.formPath + setter.formLinkPath + 'formDef/view/detailed?formDefId=' + formDefId
                    });
                    break;
                case 'preview':
                    window.open(serverPath.formPath + setter.formLinkPath +'formDef/view/formDesign/formPreview?formDefId='+formDefId);
                    break;
                case 'setPublic':
                    var isPublic = obj.data.isPublic;
                    layer.open({
                        type: 2,
                        title: "是否公开",
                        shade: 0.3,
                        area: ['300px', '150px'],
                        content: serverPath.formPath + setter.formLinkPath + 'formDef/view/setPublic?formDefId=' + formDefId +'&isPublic='+isPublic
                    });
                    break;
                case 'del':
                    layer.confirm('确定要删除选中的数据吗?',function(index){
                        $.ajax({
                            url: serverPath.formPath + setter.formLinkPath +"formDef/delByFormDefId",
                            data: {"formDefId": formDefId},
                            dataType:'json',
                            success: function (data) {
                                layer.msg(data.msg);
                                //执行重载
                                table.reload('customVersion', {
                                    page: {
                                        curr: 1
                                    }
                                });
                                parent.layui.table.reload('customForm');
                            }
                        });
                    });
                    break;
            }
        });

    });
    function closeVersions() {
        var index=parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
</script>
<style>
    #operation a{
        cursor: pointer;
    }
</style>
</body>
</html>